package service

import (
	"server_cluster/common/logger"
	"server_cluster/common/tools"
	"server_cluster/http/dao"
	"server_cluster/http/model"

	"github.com/robfig/cron/v3"
)

type Service struct {
	d                *dao.Dao
	ServerList       []*model.Region
	TimeNow          int64
	PlayerCount      int64
	AutoIncrementNum int64
	ServerStartTime  int64
}

func NewService(d *dao.Dao) (*Service, error) {
	s := &Service{
		d:                d,
		AutoIncrementNum: tools.TimeNow(),
	}
	//go s.ClearGmAccountToken()
	c := cron.New()
	_, err := c.AddFunc("@every 3600s", func() {
		err := s.CalcTowerRank()
		if err != nil {
			logger.Error("calc tower rank err:", err)
		}
	})
	if err != nil {
		return nil, err
	}
	c.Start()
	return s, nil
}
